unit uFuncionarios;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uPai, XPMenu, DB, StdCtrls, DBCtrls, Buttons, ExtCtrls, ComCtrls,
  Mask, FacDbEdit;

type
  TfFuncionarios = class(TfPai)
    Label1: TLabel;
    FacDBEdit1: TFacDBEdit;
    Label2: TLabel;
    FacDBEdit2: TFacDBEdit;
    Label3: TLabel;
    FacDBEdit3: TFacDBEdit;
    Label4: TLabel;
    FacDBEdit5: TFacDBEdit;
    Label5: TLabel;
    Panel4: TPanel;
    Panel1: TPanel;
    Label16: TLabel;
    Label11: TLabel;
    FacDBEdit6: TFacDBEdit;
    FacDBEdit7: TFacDBEdit;
    FacDBEdit8: TFacDBEdit;
    Label6: TLabel;
    FacDBEdit9: TFacDBEdit;
    Label7: TLabel;
    FacDBEdit10: TFacDBEdit;
    Label8: TLabel;
    FacDBEdit11: TFacDBEdit;
    Label9: TLabel;
    FacDBEdit12: TFacDBEdit;
    Label10: TLabel;
    FacDBEdit13: TFacDBEdit;
    Label13: TLabel;
    FacDBEdit14: TFacDBEdit;
    Label14: TLabel;
    FacDBEdit15: TFacDBEdit;
    Label15: TLabel;
    FacDBEdit16: TFacDBEdit;
    GroupBox1: TGroupBox;
    Panel5: TPanel;
    DBMemo2: TDBMemo;
    FacDBEdit4: TFacDBEdit;
    procedure btnIncluirClick(Sender: TObject);
    procedure btnProcurarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DtSrcStateChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fFuncionarios: TfFuncionarios;

implementation

uses UDM, uProcurar, uPrincipal, uAcesso, udmAcesso;

{$R *.dfm}

procedure TfFuncionarios.btnIncluirClick(Sender: TObject);
begin
  inherited;
  FacDBEdit2.SetFocus;
end;

procedure TfFuncionarios.btnProcurarClick(Sender: TObject);
begin
  inherited;

  fProcurar:=TfProcurar.Create(self,dm.proc_funcionario);
  try
   fProcurar.BtnProcurar.Click;
   fProcurar.EvDBFind1.DataField := 'NOME';
   if fProcurar.ShowModal=mrOk then
    begin
    Dm.cds_funcionario.Close;
    dm.cds_funcionario.Params[0].Clear;
    Dm.cds_funcionario.Params[0].AsInteger:=Dm.proc_funcionarioCOD_FUNCIONARIO.AsInteger;
    Dm.cds_funcionario.Open;
    end;
   finally
    dm.proc_funcionario.Close;
    fProcurar.Free;
   end;
end;

procedure TfFuncionarios.FormShow(Sender: TObject);
begin
  inherited;
  if dmAcesso.cdsFun.Active then
    dmAcesso.cdsFun.Close;
   dmAcesso.cdsFun.Params[0].AsInteger := usuarioLogado;
   dmAcesso.cdsFun.Open;

  if dmAcesso.cdsFunINCLUIR.AsString = 'S' then
    btnIncluir.Visible := true
  else
    btnIncluir.Visible := False;

  if dmAcesso.cdsFunEXCLUIR.AsString = 'S' then
    btnexcluir.Visible := true
  else
    btnexcluir.Visible := False;

  if dmAcesso.cdsFunALTERAR.AsString = 'S' then
    btngravar.Visible := true
  else
    btngravar.Visible := False;

  if dmAcesso.cdsFunCANCELAR.AsString = 'S' then
    btnCancelar.Visible := true
  else
    btnCancelar.Visible := False;
  if dmAcesso.cdsFunPROCURAR.AsString = 'S' then
    btnProcurar.Visible := true
  else
    btnProcurar.Visible := False;

 if btnIncluir.Visible = True then
    btnIncluir.SetFocus;


end;

procedure TfFuncionarios.DtSrcStateChange(Sender: TObject);
begin
  if dmAcesso.cdsFunALTERAR.AsString = 'S' then
  begin
    btngravar.Visible := True;
    btnGravar.Enabled:=DtSrc.State in [dsInsert,dsEdit];
    btnSair.Enabled:=DtSrc.State in [dsBrowse,dsInactive];
  end
  else
    DtSrc.DataSet.Cancel;
  inherited;

end;

end.
